<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "mkt_source_room".
 *
 * @property string $id
 * @property string $user_id
 * @property string $area_id
 * @property string $room_type
 * @property string $room_capacity_min
 * @property string $room_capacity_max
 */
class MktSourceRoom extends \yii\db\ActiveRecord
{
    public $parent_area_id;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'mkt_source_room';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'area_id', 'room_type', 'room_capacity_min', 'room_capacity_max'], 'integer'],
            [['parent_area_id'],'safe']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '用户编号',
            'area_id' => '场地区域',
            'room_type' => '场地类型',              // 商圈/社区, 公园/剧院, 会展/酒店, 游乐场所, 度假景点, 培训中心, 其它
            'room_capacity_min' => '场地最小容量',
            'room_capacity_max' => '场地最大容量',
        ];
    }

    /**
     * @inheritdoc
     * @return MktSourceRoomQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new MktSourceRoomQuery(get_called_class());
    }

    public function getUser()
    {
        return $this->hasOne(MktUser::className(), ['id' => 'user_id']);
    }


    static function getRoomTypeOption($key=null)
    {
        $arr = array(
            1 => '商圈/社区',
            2 => '公园/剧院',
            3 => '会展/酒店',
            4 => '游乐场所',
            5 => '度假景点',
            6 => '培训中心',
            7 => '其它',
        );        
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '');
    }

    public function getArea()
    {
        return $this->hasOne(MktArea::className(), ['id' => 'area_id']);
    }

    public function getIndustryPaths()
    {
        return empty($this->industry) ? '' : $this->industry->getPaths();
    }

    public function getAreaPaths()
    {
        return empty($this->area) ? '' : $this->area->getPaths();
    }

    public static function getCapacityMinOption($key = null)
    {
        $arr = array(
            10 => '10',
            20 => '20',
            50 => '50',
            100 => '100',
        );
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '');
    }

    public static function getCapacityMaxOption($key = null)
    {
        $arr = array(
            100 => '100',
            200 => '200',
            500 => '500',
        );
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '');
    }
    
}
